﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DeJC.DAL.Model;

namespace DeJC.BLL.Managers {
    public static class UserListManager
    {
        private static UnitOfWork unitOf = new UnitOfWork();
        public static IEnumerable<UserList> GetUserLists() {
            //IEnumerable<UserList> userLists=unitOfWork.UserListRepository.GetAll();
            //return userLists;
            return unitOf.UserListRepository.GetAll();
        }

        public static bool AddUserList(UserList userList) {
            using(UnitOfWork unitOfWork=new UnitOfWork())
            {
                userList.Deleted = false;
                userList.CreationDate=DateTime.Now;
                unitOfWork.UserListRepository.Add(userList);
                unitOfWork.Save();
            }
            return true;
        }

        //public bool UpdateUserList(UserList userList, int id) {
        public static bool UpdateUserList(UserList userList) {
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                //var userListEntity=unitOfWork.UserListRepository.GetById(id);
                //userListEntity.UserID = userList.UserID;
                unitOfWork.UserListRepository.Update(userList);
                unitOfWork.Save();
            }
            return true;
        }

        public static bool DeleteUserList(int id) {
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                UserList userList=unitOfWork.UserListRepository.GetById(id);
                userList.Deleted=true;
                userList.DeletedDate=DateTime.Now;
                unitOfWork.Save();
            }
            return true;
        }

        // public List<UserList> GetUserListPaged(int page, int rows, out int totalCount)
        // {
        // List<UserList> userLists;
        // using (UnitOfWork unitOfWork = new UnitOfWork())
        // {
        // userLists = unitOfWork.UserListRepository.GetUserListPaged
        // (page, rows, out totalCount);
        // }
        // return userLists;
        // }
        public static UserList GetById(int id) {
            UserList userList=unitOf.UserListRepository.GetById(id);
            
            return userList;
        }
    
    }
}
